package com.example.epidemic_assistant.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.epidemic_assistant.R;

import java.util.List;

public class TemperatureAdapter extends RecyclerView.Adapter<TemperatureAdapter.ViewHolder> {

    private Context mContext;
    private List<String> mTemperatureList;
    private List<String> mTemperatureDateList;

    public TemperatureAdapter(Context context, List<String> temperatureList ,  List<String> temperatureDateList) {
        mContext = context;
        mTemperatureList = temperatureList;
        mTemperatureDateList = temperatureDateList;
    }

    @NonNull
    @Override
    public TemperatureAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_temperature,parent,false));
    }

    @Override
    public void onBindViewHolder(@NonNull TemperatureAdapter.ViewHolder holder, int position) {
        String info = mTemperatureList.get(position);
        String infoDate = mTemperatureDateList.get(position);
        holder.mTvInfoDate.setText(infoDate);
        holder.mTvInfo.setText(info + "℃");
    }

    @Override
    public int getItemCount() {
        if (mTemperatureList == null) {
            return 0;
        } else {
            return mTemperatureList.size();
        }
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        private final TextView mTvInfoDate;
        private final TextView mTvInfo;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);

            mTvInfoDate = itemView.findViewById(R.id.tv_info_date);
            mTvInfo = itemView.findViewById(R.id.tv_info);
        }
    }
}
